﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using FBGraph.Configuration;

namespace FBGraph.Web.Configuration
{
    /// <summary>A collection of <see cref="FBGraphExtendedPermissionElement" /> objects.</summary>
    public class FBGraphExtendedPermissionElementCollection : ConfigurationElementCollection, IEnumerable<FBGraphExtendedPermissionElement>
    {
        /// <summary>Creates a new <see cref="FBGraphExtendedPermissionElement" />.</summary>
        protected override ConfigurationElement CreateNewElement()
        {
            return new FBGraphExtendedPermissionElement();
        }

        /// <summary>Gets the element key for the specified <paramref name="element" />.</summary>
        /// <param name="element">The <paramref name="element" />.</param>
        /// <returns>The key for the specified <paramref name="element" />.</returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((FBGraphExtendedPermissionElement)element).Permission;
        }

        #region [ IEnumerable<FBGraphExtendedPermissionElement> Members ]

        /// <summary>Gets a <see cref="IEnumerator{FBGraphExtendedPermissionElement}" /> used for iterating over the collection.</summary>
        public new IEnumerator<FBGraphExtendedPermissionElement> GetEnumerator()
        {
            return new ConfigurationElementEnumerator<FBGraphExtendedPermissionElement>(this);
        }

        #endregion

        #region [ IEnumerable Members ]

        IEnumerator IEnumerable.GetEnumerator()
        {
            return base.GetEnumerator();
        }

        #endregion
    }
}
